package leetcode.oldVersion;

//import java.util.ArrayList;

public class lc11 {
    public int maxArea(int[] height) {
        int left=0;
        int right=height.length-1;
        int area=0;
        //ArrayList<Integer> list=new ArrayList<>();

        while(left<right){//利用双指针对数组进行一次遍历，当左右指针相遇时结束循环
            int value=Math.min(height[left],height[right]);//较短线
            int newArea = value*(right-left);//面积=较短线*宽（左右指针之差）
            if(height[left]<height[right]){//左侧线短，将左指针向右侧移动
                left++;
            }
            else{//右侧线短，将右指针向左移动
                right--;
            }

            if (newArea > area){
                area=newArea;
            }
        }
        return area;
    }

    public static void main(String[] args) {
        int[] height1={1,8,6,2,5,4,8,3,7};
        int[] height2={1,1};
        lc11 lc11=new lc11();
        System.out.println(lc11.maxArea(height1));
        System.out.println(lc11.maxArea(height2));
    }
}
